/*
 * @Author: january.cjy
 * @Date: 2021-09-27 19:49:35
 * @Last Modified by: january.cjy
 * @Last Modified time: 2021-10-26 19:57:50
 */
#pragma once

#include "clang/AST/ASTConsumer.h"
#include "clang/AST/ASTContext.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/SourceManager.h"

#include <CmgRecursiveASTVisitor.h>


namespace cmg {

using namespace clang;
using namespace llvm;

class CmgASTConsumer : public clang::ASTConsumer {
public:
  explicit CmgASTConsumer(ASTContext &context, SourceManager &sm,
                          Preprocessor &pp,FileFeature &feature)
      : visitor(context, sm,feature), ctx(context), sm(sm), pp(pp) ,fileFeature(feature){}

  void HandleTranslationUnit(clang::ASTContext &Context) override {
    llvm::outs() << "CmgASTConsumer: "
                 << sm.getFileEntryForID(sm.getMainFileID())->getName() << '\n';
    this->visitor.TraverseDecl(Context.getTranslationUnitDecl());
    this->visitor.ShowOrExport();
  }

private:
  ASTContext &ctx;
  SourceManager &sm;
  Preprocessor &pp;
  FileFeature &fileFeature;
  CmgRecursiveASTVisitor visitor;
};

} // namespace cmg